package com.test.scheduleServices.check;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by wangyg6 on 2017/11/22.
 */
public class ScheduleExecutorService {
	public static void main(String[] args) {
		final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1);
		timer.scheduleAtFixedRate(new Runnable() {
			@Override
			public void run() {
				for (int i = 0; i < 100; i++) {
					if (i == 89) {
						try {
							throw new Exception("Timer任务内部异常,timer是否停止："+timer.isTerminated()+",timer是否暂停"+ timer.isShutdown());
						} catch (Exception e) {
							e.printStackTrace();
												}
					}
					System.out.println("System out is " + i);
				}
			}
		}, 0, 5, TimeUnit.SECONDS);
	}
}
